﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<string>" %>

<select data-bind="options: availablePropertyType, 
                   optionsCaption:'Please select...',
                   optionsText: 'Name',
                   optionsValue: 'PropertyType_ID'
                   " class="validate[required] chz  hide" id="vmPropertyType" name="PropertyType"></select> 
   
<script type="text/javascript">
    $(document).ready(function() {
      var selected = "";
        <% if(Model.ToString()!=""){
         %>
            selected = <%=Model.ToString()%>;
         <%}  %>
    //Begin Data
    System.Data.PropertyTypeModel = function() {
        var self = this;
        //
        self.availablePropertyType = ko.observableArray([]);
        self.selected = ko.observableArray([]);

        self.load = function() {
        $.getJSON(BASE_URL + "Listings/Ajax/GetPropertyType", function(result) {
            self.availablePropertyType(result.Data);

            $("#vmPropertyType").chosen({
                    allow_single_deselect: true
                });
                 if(selected !=""){
                           
                            $("#vmPropertyType").val(selected).trigger("liszt:updated");
                        }
                $("#vmPropertyType").removeClass("hide");
            });

        };
    }
    //Fill Data
    var vmPropertyType = new System.Data.PropertyTypeModel();
    vmPropertyType.load();
    ko.applyBindings(vmPropertyType, $("#vmPropertyType")[0]);
    
});

</script>